package stackAndQueue;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/23 12:16
 */
public class Stack {
    private final long[] array = new long[100];
    private int size = 0;

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public void push(long x) {
        array[size++] = x;
    }

    public long pop(){
        if (isEmpty()){
            throw new RuntimeException("栈空");
        }
        return array[--size];
    }
    public long peek(){
        if (isEmpty()){
            throw new RuntimeException("栈空");
        }
        return array[size - 1];
    }

    public static void main(String[] args) {
        Stack stack = new Stack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        stack.push(6);
        System.out.println(stack.peek());//6
        stack.push(7);
        System.out.println(stack.peek());//7
        stack.pop();
        System.out.println(stack.pop());//6
        System.out.println(stack.pop());//5
        System.out.println(stack.pop());//4
        System.out.println(stack.pop());//3
        System.out.println(stack.pop());//2
        System.out.println(stack.pop());//1

    }
}

